package com.kunbo.cn.controller.core.supplier;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.entity.core.supplier.SupplierUser;
import com.kunbo.cn.service.core.supplier.SupplierUserService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 * 供应商
 * @author  编写人:刘义
 * @date 时间:2019年3月18日下午1:06:25
 */
@RestController
@RequestMapping("/supplier")
public class SupplierUserController {

	@Autowired
	private SupplierUserService service;
	
	
	/**
	 * 新增
	 * @param code
	 * @param supplier
	 * @param loginName
	 * @param SupplierName
	 * @param loginPassword
	 * @param phone
	 * @param organization
	 * @param type
	 * @param effective
	 * @param explain
	 * @return
	 */
	@RequestMapping("/saveSupplier")
	public ResultBean<SupplierUser> saveSupplier(
			@RequestParam("supplier_code")String code, //编号
			@RequestParam("supplier")Integer supplier,//供应商
			@RequestParam("login_name")String loginName, //登录账户
			@RequestParam("supplier_name")String SupplierName, //供应商名称
			@RequestParam("login_password")String loginPassword, //登录密码
			@RequestParam("phone")String phone, //手机号
			@RequestParam("affiliated_organization")String organization, //所属组织
			@RequestParam("type")String type, //用户类型
			@RequestParam("effective")Integer effective, //是否有效 0  无效   1 有效
			@RequestParam("explain")String explain //说明
			){
		ResultBean<SupplierUser> result = new ResultBean<SupplierUser>();
		return BuildBean.buildResult(result, "success", "error", service.saveSupplier(code,supplier,loginName,SupplierName,loginPassword,phone,organization,type,effective,explain));
	}
	
	
	
	/**
	 * 修改
	 * @param id
	 * @param code  编码
	 * @param loginName  登录名称
	 * @param SupplierName  用户名称
	 * @param affiliated_organization 所属组织
	 * @param effective 是否有效
	 * @param loginPassword 登录密码
	 * @param phone 手机号 
	 * @param explain 说明
	 * @param type 用户类型
	 * @return
	 */
	@RequestMapping("/updSupplier")
	public ResultBean<Boolean> updSupplier(
			@RequestParam("id")String id, 
			@RequestParam("supplier_code")String code, //编号
			@RequestParam("supplier")Integer supplier,//供应商
			@RequestParam("login_name")String loginName, //登录账户
			@RequestParam("supplier_name")String SupplierName, //供应商名称
			@RequestParam("login_password")String loginPassword, //登录密码
			@RequestParam("phone")String phone, //手机号
			@RequestParam("affiliated_organization")String organization, //所属组织
			@RequestParam("type")String type, //用户类型
			@RequestParam("effective")Integer effective, //是否有效 0  无效   1 有效
			@RequestParam("explains")String explain //说明
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", service.updSupplier(id,code,supplier,loginName,SupplierName,loginPassword,phone,organization,type,effective,explain));
	}
	
	
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@RequestMapping("/delSupplier")
	public ResultBean<Boolean> updSupplier(
			@RequestParam("id")String id //id
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", service.delSupplier(id));
	}
	
	
	/**
	 * 修改密码
	 * @param id
	 * @param password  新密码
	 * @return
	 */
	@RequestMapping("/updPasword")
	public ResultBean<Boolean> updPassword(
			@RequestParam("id")String id,
			@RequestParam("password")String password
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", service.updPassword(id,password));
	}
	
	
	/**
	 * 查询
	 * @param selConditionTypeId  查询条件id
	 * @param conditionValue 条件值
	 * @param organization 所属组织
	 * @param Supplier 客户
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/selSupplier")
	public ResultBean<List<Map<String,Object>>> selSupplierList(
			@RequestParam("code")String code, 
			@RequestParam("login_name")String login_name, 
			@RequestParam("supplier")String supplier, 
			@RequestParam("page")Integer page, 
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "succes", service.selSupplierList(code,login_name,supplier,page,pageSize));
	}
	
	
}
